#include "PathNode.h"

PathNode::PathNode(void)
{
}

PathNode::PathNode(const std::string& name, Ogre::Vector3 pos, Ogre::SceneManager* pSceneManager)
	: mName(name), mpParent(NULL), mFCost(0), mGCost(0), mHCost(0), mClosed(false)
{
#ifdef _DEBUG
	setMesh("cube.mesh", pSceneManager);
	setMaterial("Examples/BumpyMetal");
#else
	mpNode = pSceneManager->getRootSceneNode()->createChildSceneNode();
#endif
	setPosition(pos);
	setScale(Ogre::Vector3(0.25,0.25,0.25));
	setShadowCaster(false);
}

PathNode::~PathNode(void)
{
	while(!mEdges.empty())
	{
		delete mEdges.back();
		mEdges.pop_back();
	}
}


void PathNode::createEdge(PathNode* pNode)
{
	Edge* pEdge = new Edge();
	pEdge->pNode = pNode;
	pEdge->moveCost = getPosition().distance(pNode->getPosition());

	mEdges.push_back(pEdge);
}

const std::string& PathNode::getName(void)
{
	return mName;
}

void PathNode::setParent(PathNode* pParent)
{
	mpParent = pParent;
}

PathNode* PathNode::getParent(void)
{
	return mpParent;
}

void PathNode::calcHCost(PathNode* pGoal)
{
	//Use the euclidean distance to the goal as a heuristic
	mHCost = mpNode->getPosition().distance(pGoal->getPosition());
}

void PathNode::calcFCost(void)
{
	mFCost = mGCost + mHCost;
}

void PathNode::setGCost(float cost)
{
	mGCost = cost;
}

float PathNode::getGCost(void)
{
	return mGCost;
}

float PathNode::getFCost(void)
{
	return mFCost;
}

void PathNode::setClosed(bool closed)
{
	mClosed = closed;
}

bool PathNode::getClosed(void)
{
	return mClosed;
}

std::vector<Edge*>* PathNode::getEdges(void)
{
	return &mEdges;
}

void PathNode::reset(void)
{
	mGCost = 0;
	mHCost = 0;
	mFCost = 0;
	mpParent = NULL;
	mClosed = false;
}